package com.gitee.ywj1352.redis;

import org.junit.Test;
import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RLexSortedSet;
import org.redisson.api.RList;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author wenjie.yang on 2019/9/25.
 */
public class RedisDemo {

    private static RedissonClient redisson;

    static {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:6379");
        redisson = Redisson.create(config);
    }

    @Test
    public void string() {
        RBucket<String> bucket=redisson.getBucket("test");
        String s = bucket.get();
        bucket.compareAndSet("ywj","ywj2");
        bucket.set("ywj",10,TimeUnit.MILLISECONDS);
        System.out.println(s);
        redisson.shutdown();
    }

    @Test
    public void list() {
        RList<Object> list = redisson.getList("test_list");
        list.add("ywj_1");
        list.add("ywj_2");
        list.add("ywj_3");
        List<Object> objects = list.get(1, 2,0);
        for (Object ob:objects)
            System.out.println(ob.toString());
    }


    @Test
    public void zset(){
        RLexSortedSet set = redisson.getLexSortedSet("lex_sorted_set");
        set.add("1");
        set.add("2");
        set.add("3");
    }







}
